package Settings;

import java.awt.Color;
import java.io.File;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Observable;

/**
 * This class contains all settings for the visualized track features and the wiggle plot.
 * @author Stefan Lorenz
 * <br><b>Date:</b> 13.12.2011
 */
@SuppressWarnings("serial")
public class FeatureAndWiggleSettings extends Observable implements Serializable{
	
	/**
	 * The index to which this settings belongs to
	 */
	private int indexOfTrack;
	/**
	 * File of parsed data
	 */
	private File file;
	/**
	 * File format
	 */
	private String typeOfFile;
	/**
	 * Are the features shown?
	 */
	private boolean isTrackShown;
	/**
	 * Y position of the features
	 */
	private int position;
	/**
	 * Color of the different type of features<br>
	 * 0: gene <br>
	 * 1: mRNA <br>
	 * 2: CDS <br>
	 * 3: other features<br>
	 * 4: read
	 */
	private Color[] color;
	/**
	 * Shape of the different feature types<br>
	 * 0: gene <br>
	 * 1: mRNA <br>
	 * 2: CDS <br>
	 * 3: other features<br>
	 * 4: read
	 */
	private int[] look;
	/**
	 * The size of the differen feature types<br>
	 * 0: gene <br>
	 * 1: mRNA <br>
	 * 2: CDS <br>
	 * 3: other features<br>
	 * 4: read
	 */
	private int[] size;
	/**
	 * Which of the different types is shown?
	 * 0: gene <br>
	 * 1: mRNA <br>
	 * 2: CDS <br>
	 * 3: other features<br>
	 * 4: read
	 */
	private boolean[] featureShown;
	/**
	 * The size of the name label
	 */
	private int labelSize;
	/**
	 * The space between the features
	 */
	private int space;
	/**
	 * The space between to bucket if they overlap
	 */
	private int bucketSpace;
	/**
	 * Show wiggle plot of features
	 */
	private boolean isReadWiggleShown;
	/**
	 * The y position of the wiggle plot
	 */
	private int positionOfReadWiggle;
	/**
	 * The size of the wiggle plot
	 */
	private int wiggleScaleSize;
	/**
	 * The size of the border of the wiggle plot
	 */
	private int wiggleFrameSize;
	/**
	 * Size of the wiggle plot
	 */
	private int sizeOfReadWiggle;
	/**
	 * Color of the wiggle plot area
	 */
	private Color colorOfWiggle;
	/**
	 * Color of the wiggle plot border
	 */
	private Color colorOfWiggleFrame;
	/**
	 * Is the wiggle plot up side down
	 */
	private boolean isUpsidedownWiggle;
	/**
	 * Is the wiggle plot filled
	 */
	private boolean isFilledWiggle;
	/**
	 * Is the wiggle plot border is dashed
	 */
	private boolean isDashedWiggle;
	/**
	 * The transparency value of the wiggle plot
	 */
	private float transparencyWiggle;
	
	/**
	 * Constructor of the standard settings
	 */
	public FeatureAndWiggleSettings() {
		this.isTrackShown = true;
		this.position = 200;
		this.space = 10;
		this.bucketSpace = 15;
		this.color = new Color[4];
		this.look = new int[4];
		this.size = new int[4];
		this.labelSize = 5;
		this.featureShown = new boolean[4];
		this.wiggleScaleSize = 10;
		this.wiggleFrameSize = 1;
		for (int i = 0; i < this.look.length; i++) {
			this.look[i] = 0;
			this.size[i] = 8;
			this.featureShown[i] = true;
			this.color[i] = Color.DARK_GRAY;
		}
		this.colorOfWiggle = Color.DARK_GRAY;
		this.colorOfWiggleFrame = Color.BLACK;
		this.isReadWiggleShown = true;
		this.positionOfReadWiggle = 250;
		this.sizeOfReadWiggle = 4;
		this.isUpsidedownWiggle = false;
		this.isFilledWiggle = false;
		this.isDashedWiggle = false;
		this.transparencyWiggle = (float) 1.0;
	}

	/**
	 * Sets the features visible or invisible
	 * @param isTrackShown are the features visible or not
	 */
	public void setTrackShown(boolean isTrackShown) {
		this.isTrackShown = isTrackShown;
	}

	/**
	 * Are the features are shown or not
	 * @return is track shown
	 */
	public boolean isTrackShown() {
		return isTrackShown;
	}

	/**
	 * Set y position of the features
	 * @param position position of the features
	 */
	public void setPosition(int position) {
		this.position = position;
		setChanged();
	}

	/**
	 * Returns the y position of the features
	 * @return the position of the features
	 */
	public int getPosition() {
		return position;
	}

	/**Sets the color of a feature type <br>
	 * 0: gene <br>
	 * 1: mRNA <br>
	 * 2: CDS <br>
	 * 3: other features<br>
	 * 4: read
	 * @param color color of the features type
	 * @param index index of the feature type
	 */
	public void setColor(Color color, int index) {
		this.color[index] = color;
		setChanged();
	}
	/**
	 * Returns the color for a feature type<br>
	 * 0: gene <br>
	 * 1: mRNA <br>
	 * 2: CDS <br>
	 * 3: other features<br>
	 * 4: read
	 * @param index index of the feature type
	 * @return the color of the feature type
	 */
	public Color getColor(int index) {
		return color[index];
	}

	/**
	 * Sets the look for feature type<br>
	 * 0: gene <br>
	 * 1: mRNA <br>
	 * 2: CDS <br>
	 * 3: other features<br>
	 * 4: read
	 * @param look index of a shape 
	 * @param index index of the feature type
	 */
	public void setLook(int look ,int index) {
		this.look[index] = look;
		setChanged();
	}


	/**
	 * Returns the look for a feature type<br>
	 * 0: gene <br>
	 * 1: mRNA <br>
	 * 2: CDS <br>
	 * 3: other features<br>
	 * 4: read
	 * @param index index of the feature type
	 * @return the index of the shape
	 * 
	 */
	public int getLook(int index) {
		return look[index];
	}

	
	/** 
	 * Sets the size for a feature type<br>
	 * 0: gene <br>
	 * 1: mRNA <br>
	 * 2: CDS <br>
	 * 3: other features<br>
	 * 4: read
	 * @param size size of the feature type
	 * @param index index of the feature type
	 */
	public void setSize(int size, int index) {
		this.size[index] = size;
		setChanged();
	}

	
	/**
	 * Returns the size for a feature type <br>
	 * 0: gene <br>
	 * 1: mRNA <br>
	 * 2: CDS <br>
	 * 3: other features<br>
	 * 4: read
	 * @return the size of a feature type
	 */
	public int getSize(int index) {
		return size[index];
	}

	/**
	 * Set the wiggle plot visible or not
	 * @param isReadWiggleShown {@link Boolean} shown or not
	 */
	public void setReadWiggleShown(boolean isReadWiggleShown) {
		this.isReadWiggleShown = isReadWiggleShown;
		setChanged();
	}

	/**
	 * Is the wiggle plot shown?
	 * @return is wiggle plot shown
	 */
	public boolean isReadWiggleShown() {
		return isReadWiggleShown;
	}

	/**
	 * Sets the position of the wiggle plot
	 * @param positionOfReadWiggle the position of the wiggle plot
	 */
	public void setPositionOfReadWiggle(int positionOfReadWiggle) {
		this.positionOfReadWiggle = positionOfReadWiggle;
		setChanged();
	}

	/**
	 * Returns the position of the wiggle plot
	 * @return the position of the wiggle plot
	 */
	public int getPositionOfReadWiggle() {
		return positionOfReadWiggle;
	}

	/**
	 * Sets the size of the wiggle plot
	 * @param sizeOfReadWiggle the size of the wiggle plot
	 */
	public void setSizeOfReadWiggle(int sizeOfReadWiggle) {
		this.sizeOfReadWiggle = sizeOfReadWiggle;
		setChanged();
	}

	/**
	 * Returns the size of the wiggle plot
	 * @return the size of the wiggle plot
	 */
	public int getSizeOfReadWiggle() {
		return sizeOfReadWiggle;
	}

	/**
	 * Sets the file of the track
	 * @param file file of the track
	 */
	public void setFile(File file) {
		this.file = file;
		setChanged();
	}

	/**
	 * Returns the file of the track
	 * @return the file of the track
	 */
	public File getFile() {
		return file;
	}

	/**
	 * Sets type of file 
	 * @param typeOfFile the type of file
	 */
	public void setTypeOfFile(String typeOfFile) {
		this.typeOfFile = typeOfFile;
		setChanged();
	}

	/**
	 * Returns the type of the file
	 * @return the type of the file
	 */
	public String getTypeOfFile() {
		return typeOfFile;
	}

	/**
	 * Sets types of feature visible or invisible
	 * 0: gene <br>
	 * 1: mRNA <br>
	 * 2: CDS <br>
	 * 3: other features<br>
	 * 4: read
	 * @param featureShown is type shown?
	 * @param index index of the type
	 */
	public void setFeatureShown(boolean featureShown, int index) {
		this.featureShown[index] = featureShown;
		setChanged();
	}

	/**
	 * Returns visibility of type of feature
	 * 0: gene <br>
	 * 1: mRNA <br>
	 * 2: CDS <br>
	 * 3: other features<br>
	 * 4: read
	 *
	 * @param index index of type
	 * @return visible or not
	 */
	public boolean getFeatureShown(int index) {
		return featureShown[index];
	}


	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
	    return "TrackSettings [indexOfTrack=" + indexOfTrack + ", file=" + file + ", typeOfFile=" + typeOfFile + ", isTrackShown=" + isTrackShown + ", position=" + position + ", color=" + Arrays.toString(color) + ", look=" + Arrays.toString(look) + ", size=" + Arrays.toString(size)
		    + ", featureShown=" + Arrays.toString(featureShown) + ", space=" + space + ", bucketSpace=" + bucketSpace + ", isReadWiggleShown=" + isReadWiggleShown + ", positionOfReadWiggle=" + positionOfReadWiggle + ", sizeOfReadWiggle=" + sizeOfReadWiggle + ", colorOfWiggle="
		    + colorOfWiggle + ", isUpsidedownWiggle=" + isUpsidedownWiggle + ", isFilledWiggle=" + isFilledWiggle + "]";
	}

	/* (non-Javadoc)
	 * @see java.util.Observable#setChanged()
	 */
	@Override
	protected synchronized void setChanged() {
		super.setChanged();
		notifyObservers();
	}

	/**
	 * Sets space between overlapping features
	 * @param space space between overlapping features
	 */
	public void setSpace(int space) {
		this.space = space;
		setChanged();
	}

	/**
	 * Returns space between overlapping features
	 * @return space between overlapping features
	 */
	public int getSpace() {
		return space;
	}

	/**
	 * Sets the space between overlapping buckets
	 * @param bucketSpace space between overlapping buckets
	 */
	public void setBucketSpace(int bucketSpace) {
		this.bucketSpace = bucketSpace;
	}

	/**
	 * Returns the space between overlapping buckets
	 * @return the space between overlapping buckets
	 */
	public int getBucketSpace() {
		return bucketSpace;
	}

	/**
	 * Sets the color of the wiggle plot area
	 * @param colorOfWiggle the color of the wiggle plot area
	 */
	public void setColorOfWiggle(Color colorOfWiggle) {
		this.colorOfWiggle = colorOfWiggle;
	}

	/**
	 * Returns the color of the wiggle plot area
	 * @return the color of the wiggle plot area
	 */
	public Color getColorOfWiggle() {
		return colorOfWiggle;
	}

	/**
	 * Sets the wiggle plot area fille or not
	 * @param isFilledWiggle is the area filled
	 */
	public void setFilledWiggle(boolean isFilledWiggle) {
	    this.isFilledWiggle = isFilledWiggle;
	}

	/**
	 * Returns {@link Boolean} if area ist fille with color or not
	 * @return is filled or not
	 */
	public boolean isFilledWiggle() {
	    return isFilledWiggle;
	}

	/**
	 * Sets the wiggle plot upside down
	 * @param isUpsidedownWiggle <code>true</code> if the wiggle plot is upside down
	 */
	public void setUpsidedownWiggle(boolean isUpsidedownWiggle) {
	    this.isUpsidedownWiggle = isUpsidedownWiggle;
	}

	/**
	 * Is the wigggle plot painted upside down
	 * @return it the wiggle plot upside down
	 */
	public boolean isUpsidedownWiggle() {
	    return isUpsidedownWiggle;
	}

	/**
	 * Sets the wiggle plot border dashed or not
	 * @param isDashedWiggle dashed or not dashed border
	 */
	public void setDashedWiggle(boolean isDashedWiggle) {
	    this.isDashedWiggle = isDashedWiggle;
	}

	/**
	 * Is the wiggle plot border dashed
	 * @return <code>true</code> if the wiggle plot border is dashed
	 */
	public boolean isDashedWiggle() {
	    return isDashedWiggle;
	}

	/**
	 * Sets the color of the wiggle plot
	 * @param colorOfWiggleFrame color of the wiggle plot
	 */
	public void setColorOfWiggleFrame(Color colorOfWiggleFrame) {
	    this.colorOfWiggleFrame = colorOfWiggleFrame;
	}

	/**
	 * Returns the color of the wiggle plot
	 * @return the color of the wiggle plot
	 */
	public Color getColorOfWiggleFrame() {
	    return colorOfWiggleFrame;
	}

	/**
	 * Sets the transparency of the wiggle plot
	 * @param transparencyWiggle transparency value of the wiggle plot
	 */
	public void setTransparencyWiggle(float transparencyWiggle) {
	    this.transparencyWiggle = transparencyWiggle;
	}

	/**
	 * Returns the transparency value of the wiggle plot
	 * @return transparency value
	 */
	public float getTransparencyWiggle() {
	    return transparencyWiggle;
	}

	/**
	 * Sets the size of the labels
	 * @param labelSize size of the labels
	 */
	public void setLabelSize(int labelSize) {
	    this.labelSize = labelSize;
	}

	/**
	 * Returns the size of the labels
	 * @return the size of the labels
	 */
	public int getLabelSize() {
	    return labelSize;
	}

	/**
	 * Sets the scale of the wiggle plot
	 * @param wiggleScaleSize scale of the wiggle plot
	 */
	public void setWiggleScaleSize(int wiggleScaleSize) {
	    this.wiggleScaleSize = wiggleScaleSize;
	}

	/**
	 * Returns scale factor of the wiggle plot
	 * @return scale factor of the wiggle plot
	 */
	public int getWiggleScaleSize() {
	    return this.wiggleScaleSize;
	}

	/**
	 * Sets the size of the wiggle plot
	 * @param wiggleFrameSize the size of the wiggle plot
	 */
	public void setWiggleFrameSize(int wiggleFrameSize) {
	    this.wiggleFrameSize = wiggleFrameSize;
	}

	/**
	 * Returns the size of the wiggle plot
	 * @return the size of the wiggle plot
	 */
	public int getWiggleFrameSize() {
	    return wiggleFrameSize;
	}	
}